﻿using Customer.API.Applcation.Command.CusContactCommand;
using Customer.Infrstructre.CusContactManager;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.CusContactCommandHandler
{
    /// <summary>
    /// 客户联系人删除
    /// </summary>
    public class DelCusContactCommandHandler:IRequestHandler<DelCusContactCommand,int>
    {
        private readonly ICusContactRepository _cusContactRep;
        public DelCusContactCommandHandler(ICusContactRepository cusContactRep)
        {
            this._cusContactRep = cusContactRep;
        }

        public async Task<int> Handle(DelCusContactCommand request, CancellationToken cancellationToken)
        {
            foreach (var item in request.CusContactId)
            {
                var list = await _cusContactRep.GetModelAsync(item);
                list.IsDel = true;
                await _cusContactRep.Update(list);
            }
            return 1;
        }
    }
}
